package com.jms.fu.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.jms.fu.exception.DAOException;
import com.jms.fu.form.UploadForm;
import com.jms.fu.model.bean.App;
import com.jms.fu.model.bo.AppBO;

public class DirectorUpdateAppAction extends Action{

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		
		try {
			int appid = Integer.parseInt(request.getParameter("appid"));
			request.setAttribute("appid", appid);
			String username = (String)request.getSession().getAttribute("username");
			String role = (String) request.getSession().getAttribute("role");
			AppBO appbo = new AppBO();
			String devId = appbo.getAppByID(appid).getDevId();
			
			if(devId.equals(username)||"Administrator".equals(role)){
				return mapping.findForward("success");	
			}else{
				return mapping.findForward("success");	
			}
			
		} catch (NumberFormatException | DAOException | NullPointerException e) {
			return mapping.findForward("failed");
		}
		
		
	}
	
}
